const mysql = require('mysql2/promise');

// 创建 MySQL 连接池
const pool = mysql.createPool({
  host: 'localhost', // 数据库地址
  user: 'root',      // 数据库用户名
  password: 'password', // 数据库密码
  database: 'canteen',  // 数据库名称
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0
});

// 查询方法
async function query(sql, params) {
  const connection = await pool.getConnection();
  try {
    const [rows] = await connection.execute(sql, params);
    return rows;
  } finally {
    connection.release();
  }
}

module.exports = {
  query
}; 